
public class LinkedQueue<E extends Comparable> {

	private class LinkedNode<E>{
		
		private E data;
		private LinkedNode<E> next;
		
		public LinkedNode(E item){
			this.data = item;
			this.next = null;
		}
		
		public void setNext(LinkedNode<E> next){
			this.next = next;
		}
		
		public LinkedNode<E> getNext(){
			return this.next;
		}
		
		@SuppressWarnings("unused")
		public void setData(E item){
			this.data = item;
		}
		
		public E getData(){
			return this.data;
		}
	}
	
	private LinkedNode<E> head;
	private LinkedNode<E> tail;
	
	public LinkedQueue(){
		this.head = null;
		this.tail = null;
	}
	
	@SuppressWarnings("unchecked")
	public boolean offer(E item){
		if(item == null){
			return false;
		}
		
		LinkedNode<E> newNode;
		
		if(this.head != null){
			LinkedNode<E> curr = this.head;
			while(curr != null){
				if(curr.getData().compareTo(item) == 0){
					return false;
				}
				curr = curr.getNext();
			}
			newNode = new LinkedNode<E>(item);
			this.tail.setNext(newNode);
			this.tail = newNode;
			return true;
		}
		
		newNode = new LinkedNode<E>(item);
		this.head = newNode;
		this.tail = newNode;
		return true;
	}
	
	public E poll(){
		if(this.head != null){
			E temp = head.getData();
			if(this.head == this.tail){
				this.head = null;
				this.tail = null;
			}else{
				this.head = this.head.getNext();
			}
			return temp;
		}
		System.out.println("The queue is empty.");
		return null;
	}
}
